﻿@using Finbuckle.MultiTenant.Abstractions
@using Finbuckle.MultiTenant.AspNetCore.Extensions
@using Microsoft.AspNetCore.Identity
@inject SignInManager<IdentityUser> SignInManager
@inject UserManager<IdentityUser> UserManager
@inject IMultiTenantStore<AppTenantInfo> TenantStore;

<ul class="navbar-nav">
    <li class="nav-item dropdown">
        <a class="nav-link dropdown-toggle text-light text-bg-secondary" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
            @(Context.GetTenantInfo<AppTenantInfo>()?.Name ?? "Select Tenant")
        </a>
        <ul class="dropdown-menu">
            <li><a class="dropdown-item" asp-controller="Home" asp-action="Index" asp-route-__tenant__="">No Tenant</a></li>
            @foreach (var tenant in await TenantStore.GetAllAsync())
            {
                <li><a class="dropdown-item" asp-controller="Home" asp-action="Index" asp-route-__tenant__="@tenant.Identifier">@tenant.Name</a></li>
            }
        </ul>
    </li>
    @if (SignInManager.IsSignedIn(User))
    {
        <li class="nav-item">
            <a class="nav-link text-dark" asp-area="Identity" asp-page="/Account/Manage/Index" title="Manage">@User.Identity?.Name</a>
        </li>
        <li class="nav-item">
            <form class="form-inline" asp-area="Identity" asp-page="/Account/Logout" asp-route-returnUrl="@Url.Action("Index", "Home", new { area = "" })">
                <button type="submit" class="nav-link btn btn-link text-dark">Logout</button>
            </form>
        </li>
    }
    else
    {
        <li class="nav-item">
            <a class="nav-link text-dark" asp-area="Identity" asp-page="/Account/Register">Register</a>
        </li>
        <li class="nav-item">
            <a class="nav-link text-dark" asp-area="Identity" asp-page="/Account/Login" asp-route-returnUrl="@Url.Action("Index", "Home", new { area = "" })">Login</a>
        </li>
    }
</ul>